package top.lyjwn.todo.weinxin.api.bjnews;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.lyjwn.todo.weinxin.api.url.WXBjnewsUrl;
import top.lyjwn.todo.weinxin.bjnews.BjnewsAccessToken;
import top.lyjwn.todo.weinxin.data.bjnews.WXBMessage;
import top.lyjwn.todo.common.utils.http.HttpUtil;

/**
 * 客服接口-发消息
 *
 * @author luoyujie
 */
@Component
public class ServiceSendMessage {

    @Autowired
    private WXBjnewsUrl wxBjnewsUrl;


    public ServiceSendMessage() {
    }


    public String getUrl(BjnewsAccessToken accessToken) {
        String url = wxBjnewsUrl.getSERVICE_SEND_MESSAGE().replace("#{ACCESS_TOKEN}", accessToken.getAccess_token());
        return url;
    }

    public String getResultString(BjnewsAccessToken accessToken, WXBMessage wXBMessage) {
        String jsonString = wXBMessage.toJSONString();
        String result = HttpUtil.request(getUrl(accessToken), HttpUtil.METHOD_POST, jsonString);
        return result;
    }


    public JSONObject getResultJSONObject(BjnewsAccessToken accessToken, WXBMessage wXBMessage) {
        String resultString = this.getResultString(accessToken, wXBMessage);
        return JSONObject.parseObject(resultString);
    }

}
